{include file="header.html"}
<body class="gr">

<div class="navBar">
	<a class="left" href="javascript:history.back()"><i class="return"></i></a>
	<div class="titleView-x">活动区</div>
</div>

<div class="shop-ads main-padding-top">
	<div class="pullRefresh">
		{if count($data.ads)>0}
		<ul class="ads">
			{foreach from=$data.ads name=g item=g}
			<li ad_type="{$g->ad_type}" ad_content="{$g->ad_content}" pic="{$g->pic}"></li>
			{/foreach}
		</ul>
		{/if}
	</div>
</div>

{include file="footer.html"}
<script>
var offset = $('.pullRefresh .list > li').length;
function createHtml(g){
	var html = '<li ad_type="'+g.ad_type+'" ad_content="'+g.ad_content+'" pic="'+g.pic+'"></li>';
	offset++;
	return html;
}
function resize(){
	$('.shop-ads .ads li').autoHeight(320, 103);
}
$(window).resize(resize);
$(function(){
	resize();
	setAds('.shop-ads .ads li');
	$('.shop-ads').height($.window().height-$('.shop-ads').padding().top);
	$('.pullRefresh').pullRefresh({
		header : true,
		footer : true,
		footerNoMoreText : '- END -',
		refresh : function(fn){
			var _this = this;
			offset = 0;
			$.getJSON('api.php?app=shop&act=ads', function(json){
				if(json.error!=0){ $.overloadError(json.msg);return }
				var html = '';
				if($.isArray(json.data))for(var i=0; i<json.data.length; i++)html += createHtml(json.data[i]);
				_this.find('.list').html(html);
				setAds('.shop-ads .ads li');
				fn();
			});
		},
		load : function(fn){
			var _this = this;
			$.getJSON('api.php?app=shop&act=ads', { offset:offset }, function(json){
				if(json.error!=0){ $.overloadError(json.msg);return }
				var html = '';
				if($.isArray(json.data))for(var i=0; i<json.data.length; i++)html += createHtml(json.data[i]);
				_this.find('.list').append(html);
				setAds('.shop-ads .ads li');
				fn();
			});
		}
	});
});
</script>